package day15.synchronizeddemo;

public class AccountDemo {
    public static void main(String[] args) {
        Runnable r = new AccountThread();
        Thread husband = new Thread(r);
        husband.setName("文章：");
        Thread wife = new Thread(r);
        wife.setName("马伊琍：");
        husband.start();
        wife.start();
    }


}
class AccountThread implements Runnable {
    private Account acc=new Account();
    public  void withdraw(double money){
        synchronized (acc){
            System.out.println(Thread.currentThread().getName()+"正在取款...");
            acc.withdraw(money);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+",完成取款,余额是:"+acc.getMoney());

        }
    }
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            withdraw(10);
        }

    }
}





